<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/4/12
 * Time: 15:08
 */

namespace App\Rep;


use App\Models\Supplier;

class SupplierRep
{

    /**
     * 获取供应商列表
     * @param $params
     */
    public function getSupplierListRep($params){
        return Supplier::Search($params)
            ->orderBy('id','desc')
            ->paginate($params['per_page']??1000);
    }

    /**
     * 添加供应商
     * @param $params
     */
    public function createSupplierRep($params){
        if(isset($params['id']) && !empty($params['id'])){
            $model = Supplier::where('id',$params['id'])->first();
        }else{
            $model = new Supplier();
        }
        $model->code = $params['code'];
        $model->name = $params['name'];
        $model->type = $params['type'];
        $model->link_man = $params['link_man'];
        $model->tel = $params['tel'];
        $model->address = $params['address'];
        $model->bank_name = $params['bank_name'];
        $model->bank_account = $params['bank_account'];
        $model->save();
        return ['code'=>0,'data'=>$model,'msg'=>'success'];
    }

    /**
     * 删除供应商
     * @param $params
     */
    public function delSupplierRep($params){
        $model = Supplier::where('id',$params['id'])->first();
        $model->is_del = $params['is_del'];
        $model->save();
        return ['code'=>0,'data'=>$model,'msg'=>'success'];
    }

}